package com.bw.tap.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.bw.lib_core.mvvm.viewmodel.BaseViewModel;
import com.bw.tap.R;
import com.bw.tap.databinding.ViewContentLayoutBinding;
import com.bw.tap.view.TitleView;

/**
 * 带标题栏的Act
 */
public abstract class TitleBarActivity<V extends ViewDataBinding, VM extends BaseViewModel> extends BaseBarActivity<V, VM> implements ITitleBar {

    private ViewContentLayoutBinding contentLayoutBinding;

    @Override
    public void initBinding() {
        contentLayoutBinding = DataBindingUtil.setContentView(this, R.layout.view_content_layout);
        LinearLayout root = (LinearLayout) contentLayoutBinding.getRoot();
        if (bandingLayout() != 0) {
            mDataBinding = DataBindingUtil.inflate(LayoutInflater.from(this), bandingLayout(), root, false);
        }
        //添加内容区域
        root.addView(mDataBinding.getRoot());
    }

    @Override
    public void registerBack() {
        registerBackCustom(R.mipmap.detail_icon_back_grey, null, null);
    }

    @Override
    public void registerBackCustom(int imgId, String liftName, View.OnClickListener onClickListener) {
        if (imgId > 0) {
            contentLayoutBinding.titleView.getLeftBackImageTv().setImageResource(imgId);
        }
        if (liftName != null) {
            contentLayoutBinding.titleView.getLeftBackTextTv().setText(liftName);
        }
        if (onClickListener != null) {
            contentLayoutBinding.titleView.getLeftBackImageTv().setOnClickListener(onClickListener);
        } else {
            contentLayoutBinding.titleView.getLeftBackImageTv().setOnClickListener(this);
        }
    }

    @Override
    public void setTitleName(String titleName) {

    }

    @Override
    public void setTitleNameCustom(String titleName, int color, int size) {

    }

    @Override
    public void setSubTitleName(String titleName) {

    }

    @Override
    public void setSubTitleNameCustom(String titleName, int color, int size) {

    }

    @Override
    public void addRightBtn(TitleRightBtn btn) {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v.getId() == R.id.iv_left_image) {
            finish();
        }
    }
}
